home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 1999 August / SGI Freeware 1999 August.iso / dist / fw_xemacs.idb / usr / freeware / lib / xemacs-20.4 / info / lispref.info-9.z / lispref.info-9
Encoding:
GNU Info File  |  1998-05-21  |  49.5 KB  |  1,210 lines

  1. This is Info file ../../info/lispref.info, produced by Makeinfo version
  2. 1.68 from the input file lispref.texi.
  3.  
  4.    Edition History:
  5.  
  6.    GNU Emacs Lisp Reference Manual Second Edition (v2.01), May 1993 GNU
  7. Emacs Lisp Reference Manual Further Revised (v2.02), August 1993 Lucid
  8. Emacs Lisp Reference Manual (for 19.10) First Edition, March 1994
  9. XEmacs Lisp Programmer's Manual (for 19.12) Second Edition, April 1995
  10. GNU Emacs Lisp Reference Manual v2.4, June 1995 XEmacs Lisp
  11. Programmer's Manual (for 19.13) Third Edition, July 1995 XEmacs Lisp
  12. Reference Manual (for 19.14 and 20.0) v3.1, March 1996 XEmacs Lisp
  13. Reference Manual (for 19.15 and 20.1, 20.2) v3.2, April, May 1997
  14.  
  15.    Copyright (C) 1990, 1991, 1992, 1993, 1994, 1995 Free Software
  16. Foundation, Inc.  Copyright (C) 1994, 1995 Sun Microsystems, Inc.
  17. Copyright (C) 1995, 1996 Ben Wing.
  18.  
  19.    Permission is granted to make and distribute verbatim copies of this
  20. manual provided the copyright notice and this permission notice are
  21. preserved on all copies.
  22.  
  23.    Permission is granted to copy and distribute modified versions of
  24. this manual under the conditions for verbatim copying, provided that the
  25. entire resulting derived work is distributed under the terms of a
  26. permission notice identical to this one.
  27.  
  28.    Permission is granted to copy and distribute translations of this
  29. manual into another language, under the above conditions for modified
  30. versions, except that this permission notice may be stated in a
  31. translation approved by the Foundation.
  32.  
  33.    Permission is granted to copy and distribute modified versions of
  34. this manual under the conditions for verbatim copying, provided also
  35. that the section entitled "GNU General Public License" is included
  36. exactly as in the original, and provided that the entire resulting
  37. derived work is distributed under the terms of a permission notice
  38. identical to this one.
  39.  
  40.    Permission is granted to copy and distribute translations of this
  41. manual into another language, under the above conditions for modified
  42. versions, except that the section entitled "GNU General Public License"
  43. may be included in a translation approved by the Free Software
  44. Foundation instead of in the original English.
  45.  
  46. 
  47. File: lispref.info,  Node: Cleanups,  Prev: Errors,  Up: Nonlocal Exits
  48.  
  49. Cleaning Up from Nonlocal Exits
  50. -------------------------------
  51.  
  52.    The `unwind-protect' construct is essential whenever you temporarily
  53. put a data structure in an inconsistent state; it permits you to ensure
  54. the data are consistent in the event of an error or throw.
  55.  
  56.  - Special Form: unwind-protect BODY CLEANUP-FORMS...
  57.      `unwind-protect' executes the BODY with a guarantee that the
  58.      CLEANUP-FORMS will be evaluated if control leaves BODY, no matter
  59.      how that happens.  The BODY may complete normally, or execute a
  60.      `throw' out of the `unwind-protect', or cause an error; in all
  61.      cases, the CLEANUP-FORMS will be evaluated.
  62.  
  63.      If the BODY forms finish normally, `unwind-protect' returns the
  64.      value of the last BODY form, after it evaluates the CLEANUP-FORMS.
  65.      If the BODY forms do not finish, `unwind-protect' does not return
  66.      any value in the normal sense.
  67.  
  68.      Only the BODY is actually protected by the `unwind-protect'.  If
  69.      any of the CLEANUP-FORMS themselves exits nonlocally (e.g., via a
  70.      `throw' or an error), `unwind-protect' is *not* guaranteed to
  71.      evaluate the rest of them.  If the failure of one of the
  72.      CLEANUP-FORMS has the potential to cause trouble, then protect it
  73.      with another `unwind-protect' around that form.
  74.  
  75.      The number of currently active `unwind-protect' forms counts,
  76.      together with the number of local variable bindings, against the
  77.      limit `max-specpdl-size' (*note Local Variables::.).
  78.  
  79.    For example, here we make an invisible buffer for temporary use, and
  80. make sure to kill it before finishing:
  81.  
  82.      (save-excursion
  83.        (let ((buffer (get-buffer-create " *temp*")))
  84.          (set-buffer buffer)
  85.          (unwind-protect
  86.              BODY
  87.            (kill-buffer buffer))))
  88.  
  89. You might think that we could just as well write `(kill-buffer
  90. (current-buffer))' and dispense with the variable `buffer'.  However,
  91. the way shown above is safer, if BODY happens to get an error after
  92. switching to a different buffer!  (Alternatively, you could write
  93. another `save-excursion' around the body, to ensure that the temporary
  94. buffer becomes current in time to kill it.)
  95.  
  96.    Here is an actual example taken from the file `ftp.el'.  It creates
  97. a process (*note Processes::.) to try to establish a connection to a
  98. remote machine.  As the function `ftp-login' is highly susceptible to
  99. numerous problems that the writer of the function cannot anticipate, it
  100. is protected with a form that guarantees deletion of the process in the
  101. event of failure.  Otherwise, XEmacs might fill up with useless
  102. subprocesses.
  103.  
  104.      (let ((win nil))
  105.        (unwind-protect
  106.            (progn
  107.              (setq process (ftp-setup-buffer host file))
  108.              (if (setq win (ftp-login process host user password))
  109.                  (message "Logged in")
  110.                (error "Ftp login failed")))
  111.          (or win (and process (delete-process process)))))
  112.  
  113.    This example actually has a small bug: if the user types `C-g' to
  114. quit, and the quit happens immediately after the function
  115. `ftp-setup-buffer' returns but before the variable `process' is set,
  116. the process will not be killed.  There is no easy way to fix this bug,
  117. but at least it is very unlikely.
  118.  
  119.    Here is another example which uses `unwind-protect' to make sure to
  120. kill a temporary buffer.  In this example, the value returned by
  121. `unwind-protect' is used.
  122.  
  123.      (defun shell-command-string (cmd)
  124.        "Return the output of the shell command CMD, as a string."
  125.        (save-excursion
  126.          (set-buffer (generate-new-buffer " OS*cmd"))
  127.          (shell-command cmd t)
  128.          (unwind-protect
  129.              (buffer-string)
  130.            (kill-buffer (current-buffer)))))
  131.  
  132. 
  133. File: lispref.info,  Node: Variables,  Next: Functions,  Prev: Control Structures,  Up: Top
  134.  
  135. Variables
  136. *********
  137.  
  138.    A "variable" is a name used in a program to stand for a value.
  139. Nearly all programming languages have variables of some sort.  In the
  140. text of a Lisp program, variables are written using the syntax for
  141. symbols.
  142.  
  143.    In Lisp, unlike most programming languages, programs are represented
  144. primarily as Lisp objects and only secondarily as text.  The Lisp
  145. objects used for variables are symbols: the symbol name is the variable
  146. name, and the variable's value is stored in the value cell of the
  147. symbol.  The use of a symbol as a variable is independent of its use as
  148. a function name.  *Note Symbol Components::.
  149.  
  150.    The Lisp objects that constitute a Lisp program determine the textual
  151. form of the program--it is simply the read syntax for those Lisp
  152. objects.  This is why, for example, a variable in a textual Lisp program
  153. is written using the read syntax for the symbol that represents the
  154. variable.
  155.  
  156. * Menu:
  157.  
  158. * Global Variables::      Variable values that exist permanently, everywhere.
  159. * Constant Variables::    Certain "variables" have values that never change.
  160. * Local Variables::       Variable values that exist only temporarily.
  161. * Void Variables::        Symbols that lack values.
  162. * Defining Variables::    A definition says a symbol is used as a variable.
  163. * Accessing Variables::   Examining values of variables whose names
  164.                             are known only at run time.
  165. * Setting Variables::     Storing new values in variables.
  166. * Variable Scoping::      How Lisp chooses among local and global values.
  167. * Buffer-Local Variables::  Variable values in effect only in one buffer.
  168. * Variable Aliases::      Making one variable point to another.
  169.  
  170. 
  171. File: lispref.info,  Node: Global Variables,  Next: Constant Variables,  Up: Variables
  172.  
  173. Global Variables
  174. ================
  175.  
  176.    The simplest way to use a variable is "globally".  This means that
  177. the variable has just one value at a time, and this value is in effect
  178. (at least for the moment) throughout the Lisp system.  The value remains
  179. in effect until you specify a new one.  When a new value replaces the
  180. old one, no trace of the old value remains in the variable.
  181.  
  182.    You specify a value for a symbol with `setq'.  For example,
  183.  
  184.      (setq x '(a b))
  185.  
  186. gives the variable `x' the value `(a b)'.  Note that `setq' does not
  187. evaluate its first argument, the name of the variable, but it does
  188. evaluate the second argument, the new value.
  189.  
  190.    Once the variable has a value, you can refer to it by using the
  191. symbol by itself as an expression.  Thus,
  192.  
  193.      x => (a b)
  194.  
  195. assuming the `setq' form shown above has already been executed.
  196.  
  197.    If you do another `setq', the new value replaces the old one:
  198.  
  199.      x
  200.           => (a b)
  201.      (setq x 4)
  202.           => 4
  203.      x
  204.           => 4
  205.  
  206. 
  207. File: lispref.info,  Node: Constant Variables,  Next: Local Variables,  Prev: Global Variables,  Up: Variables
  208.  
  209. Variables That Never Change
  210. ===========================
  211.  
  212.    XEmacs Lisp has two special symbols, `nil' and `t', that always
  213. evaluate to themselves.  These symbols cannot be rebound, nor can their
  214. value cells be changed.  An attempt to change the value of `nil' or `t'
  215. signals a `setting-constant' error.
  216.  
  217.      nil == 'nil
  218.           => nil
  219.      (setq nil 500)
  220.      error--> Attempt to set constant symbol: nil
  221.  
  222. 
  223. File: lispref.info,  Node: Local Variables,  Next: Void Variables,  Prev: Constant Variables,  Up: Variables
  224.  
  225. Local Variables
  226. ===============
  227.  
  228.    Global variables have values that last until explicitly superseded
  229. with new values.  Sometimes it is useful to create variable values that
  230. exist temporarily--only while within a certain part of the program.
  231. These values are called "local", and the variables so used are called
  232. "local variables".
  233.  
  234.    For example, when a function is called, its argument variables
  235. receive new local values that last until the function exits.  The `let'
  236. special form explicitly establishes new local values for specified
  237. variables; these last until exit from the `let' form.
  238.  
  239.    Establishing a local value saves away the previous value (or lack of
  240. one) of the variable.  When the life span of the local value is over,
  241. the previous value is restored.  In the mean time, we say that the
  242. previous value is "shadowed" and "not visible".  Both global and local
  243. values may be shadowed (*note Scope::.).
  244.  
  245.    If you set a variable (such as with `setq') while it is local, this
  246. replaces the local value; it does not alter the global value, or
  247. previous local values that are shadowed.  To model this behavior, we
  248. speak of a "local binding" of the variable as well as a local value.
  249.  
  250.    The local binding is a conceptual place that holds a local value.
  251. Entry to a function, or a special form such as `let', creates the local
  252. binding; exit from the function or from the `let' removes the local
  253. binding.  As long as the local binding lasts, the variable's value is
  254. stored within it.  Use of `setq' or `set' while there is a local
  255. binding stores a different value into the local binding; it does not
  256. create a new binding.
  257.  
  258.    We also speak of the "global binding", which is where (conceptually)
  259. the global value is kept.
  260.  
  261.    A variable can have more than one local binding at a time (for
  262. example, if there are nested `let' forms that bind it).  In such a
  263. case, the most recently created local binding that still exists is the
  264. "current binding" of the variable.  (This is called "dynamic scoping";
  265. see *Note Variable Scoping::.)  If there are no local bindings, the
  266. variable's global binding is its current binding.  We also call the
  267. current binding the "most-local existing binding", for emphasis.
  268. Ordinary evaluation of a symbol always returns the value of its current
  269. binding.
  270.  
  271.    The special forms `let' and `let*' exist to create local bindings.
  272.  
  273.  - Special Form: let (BINDINGS...) FORMS...
  274.      This special form binds variables according to BINDINGS and then
  275.      evaluates all of the FORMS in textual order.  The `let'-form
  276.      returns the value of the last form in FORMS.
  277.  
  278.      Each of the BINDINGS is either (i) a symbol, in which case that
  279.      symbol is bound to `nil'; or (ii) a list of the form `(SYMBOL
  280.      VALUE-FORM)', in which case SYMBOL is bound to the result of
  281.      evaluating VALUE-FORM.  If VALUE-FORM is omitted, `nil' is used.
  282.  
  283.      All of the VALUE-FORMs in BINDINGS are evaluated in the order they
  284.      appear and *before* any of the symbols are bound.  Here is an
  285.      example of this: `Z' is bound to the old value of `Y', which is 2,
  286.      not the new value, 1.
  287.  
  288.           (setq Y 2)
  289.                => 2
  290.           (let ((Y 1)
  291.                 (Z Y))
  292.             (list Y Z))
  293.                => (1 2)
  294.  
  295.  - Special Form: let* (BINDINGS...) FORMS...
  296.      This special form is like `let', but it binds each variable right
  297.      after computing its local value, before computing the local value
  298.      for the next variable.  Therefore, an expression in BINDINGS can
  299.      reasonably refer to the preceding symbols bound in this `let*'
  300.      form.  Compare the following example with the example above for
  301.      `let'.
  302.  
  303.           (setq Y 2)
  304.                => 2
  305.           (let* ((Y 1)
  306.                  (Z Y))    ; Use the just-established value of `Y'.
  307.             (list Y Z))
  308.                => (1 1)
  309.  
  310.    Here is a complete list of the other facilities that create local
  311. bindings:
  312.  
  313.    * Function calls (*note Functions::.).
  314.  
  315.    * Macro calls (*note Macros::.).
  316.  
  317.    * `condition-case' (*note Errors::.).
  318.  
  319.    Variables can also have buffer-local bindings (*note Buffer-Local
  320. Variables::.).  These kinds of bindings work somewhat like ordinary
  321. local bindings, but they are localized depending on "where" you are in
  322. Emacs, rather than localized in time.
  323.  
  324.  - Variable: max-specpdl-size
  325.      This variable defines the limit on the total number of local
  326.      variable bindings and `unwind-protect' cleanups (*note Nonlocal
  327.      Exits::.)  that are allowed before signaling an error (with data
  328.      `"Variable binding depth exceeds max-specpdl-size"').
  329.  
  330.      This limit, with the associated error when it is exceeded, is one
  331.      way that Lisp avoids infinite recursion on an ill-defined function.
  332.  
  333.      The default value is 600.
  334.  
  335.      `max-lisp-eval-depth' provides another limit on depth of nesting.
  336.      *Note Eval::.
  337.  
  338. 
  339. File: lispref.info,  Node: Void Variables,  Next: Defining Variables,  Prev: Local Variables,  Up: Variables
  340.  
  341. When a Variable is "Void"
  342. =========================
  343.  
  344.    If you have never given a symbol any value as a global variable, we
  345. say that that symbol's global value is "void".  In other words, the
  346. symbol's value cell does not have any Lisp object in it.  If you try to
  347. evaluate the symbol, you get a `void-variable' error rather than a
  348. value.
  349.  
  350.    Note that a value of `nil' is not the same as void.  The symbol
  351. `nil' is a Lisp object and can be the value of a variable just as any
  352. other object can be; but it is *a value*.  A void variable does not
  353. have any value.
  354.  
  355.    After you have given a variable a value, you can make it void once
  356. more using `makunbound'.
  357.  
  358.  - Function: makunbound SYMBOL
  359.      This function makes the current binding of SYMBOL void.
  360.      Subsequent attempts to use this symbol's value as a variable will
  361.      signal the error `void-variable', unless or until you set it again.
  362.  
  363.      `makunbound' returns SYMBOL.
  364.  
  365.           (makunbound 'x)      ; Make the global value
  366.                                ;   of `x' void.
  367.                => x
  368.           x
  369.           error--> Symbol's value as variable is void: x
  370.  
  371.      If SYMBOL is locally bound, `makunbound' affects the most local
  372.      existing binding.  This is the only way a symbol can have a void
  373.      local binding, since all the constructs that create local bindings
  374.      create them with values.  In this case, the voidness lasts at most
  375.      as long as the binding does; when the binding is removed due to
  376.      exit from the construct that made it, the previous or global
  377.      binding is reexposed as usual, and the variable is no longer void
  378.      unless the newly reexposed binding was void all along.
  379.  
  380.           (setq x 1)               ; Put a value in the global binding.
  381.                => 1
  382.           (let ((x 2))             ; Locally bind it.
  383.             (makunbound 'x)        ; Void the local binding.
  384.             x)
  385.           error--> Symbol's value as variable is void: x
  386.  
  387.           x                        ; The global binding is unchanged.
  388.                => 1
  389.           
  390.           (let ((x 2))             ; Locally bind it.
  391.             (let ((x 3))           ; And again.
  392.               (makunbound 'x)      ; Void the innermost-local binding.
  393.               x))                  ; And refer: it's void.
  394.           error--> Symbol's value as variable is void: x
  395.  
  396.           (let ((x 2))
  397.             (let ((x 3))
  398.               (makunbound 'x))     ; Void inner binding, then remove it.
  399.             x)                     ; Now outer `let' binding is visible.
  400.                => 2
  401.  
  402.    A variable that has been made void with `makunbound' is
  403. indistinguishable from one that has never received a value and has
  404. always been void.
  405.  
  406.    You can use the function `boundp' to test whether a variable is
  407. currently void.
  408.  
  409.  - Function: boundp VARIABLE
  410.      `boundp' returns `t' if VARIABLE (a symbol) is not void; more
  411.      precisely, if its current binding is not void.  It returns `nil'
  412.      otherwise.
  413.  
  414.           (boundp 'abracadabra)          ; Starts out void.
  415.                => nil
  416.  
  417.           (let ((abracadabra 5))         ; Locally bind it.
  418.             (boundp 'abracadabra))
  419.                => t
  420.  
  421.           (boundp 'abracadabra)          ; Still globally void.
  422.                => nil
  423.  
  424.           (setq abracadabra 5)           ; Make it globally nonvoid.
  425.                => 5
  426.  
  427.           (boundp 'abracadabra)
  428.                => t
  429.  
  430. 
  431. File: lispref.info,  Node: Defining Variables,  Next: Accessing Variables,  Prev: Void Variables,  Up: Variables
  432.  
  433. Defining Global Variables
  434. =========================
  435.  
  436.    You may announce your intention to use a symbol as a global variable
  437. with a "variable definition": a special form, either `defconst' or
  438. `defvar'.
  439.  
  440.    In XEmacs Lisp, definitions serve three purposes.  First, they inform
  441. people who read the code that certain symbols are *intended* to be used
  442. a certain way (as variables).  Second, they inform the Lisp system of
  443. these things, supplying a value and documentation.  Third, they provide
  444. information to utilities such as `etags' and `make-docfile', which
  445. create data bases of the functions and variables in a program.
  446.  
  447.    The difference between `defconst' and `defvar' is primarily a matter
  448. of intent, serving to inform human readers of whether programs will
  449. change the variable.  XEmacs Lisp does not restrict the ways in which a
  450. variable can be used based on `defconst' or `defvar' declarations.
  451. However, it does make a difference for initialization: `defconst'
  452. unconditionally initializes the variable, while `defvar' initializes it
  453. only if it is void.
  454.  
  455.    One would expect user option variables to be defined with
  456. `defconst', since programs do not change them.  Unfortunately, this has
  457. bad results if the definition is in a library that is not preloaded:
  458. `defconst' would override any prior value when the library is loaded.
  459. Users would like to be able to set user options in their init files,
  460. and override the default values given in the definitions.  For this
  461. reason, user options must be defined with `defvar'.
  462.  
  463.  - Special Form: defvar SYMBOL [VALUE [DOC-STRING]]
  464.      This special form defines SYMBOL as a value and initializes it.
  465.      The definition informs a person reading your code that SYMBOL is
  466.      used as a variable that programs are likely to set or change.  It
  467.      is also used for all user option variables except in the preloaded
  468.      parts of XEmacs.  Note that SYMBOL is not evaluated; the symbol to
  469.      be defined must appear explicitly in the `defvar'.
  470.  
  471.      If SYMBOL already has a value (i.e., it is not void), VALUE is not
  472.      even evaluated, and SYMBOL's value remains unchanged.  If SYMBOL
  473.      is void and VALUE is specified, `defvar' evaluates it and sets
  474.      SYMBOL to the result.  (If VALUE is omitted, the value of SYMBOL
  475.      is not changed in any case.)
  476.  
  477.      When you evaluate a top-level `defvar' form with `C-M-x' in Emacs
  478.      Lisp mode (`eval-defun'), a special feature of `eval-defun'
  479.      evaluates it as a `defconst'.  The purpose of this is to make sure
  480.      the variable's value is reinitialized, when you ask for it
  481.      specifically.
  482.  
  483.      If SYMBOL has a buffer-local binding in the current buffer,
  484.      `defvar' sets the default value, not the local value.  *Note
  485.      Buffer-Local Variables::.
  486.  
  487.      If the DOC-STRING argument appears, it specifies the documentation
  488.      for the variable.  (This opportunity to specify documentation is
  489.      one of the main benefits of defining the variable.)  The
  490.      documentation is stored in the symbol's `variable-documentation'
  491.      property.  The XEmacs help functions (*note Documentation::.) look
  492.      for this property.
  493.  
  494.      If the first character of DOC-STRING is `*', it means that this
  495.      variable is considered a user option.  This lets users set the
  496.      variable conventiently using the commands `set-variable' and
  497.      `edit-options'.
  498.  
  499.      For example, this form defines `foo' but does not set its value:
  500.  
  501.           (defvar foo)
  502.                => foo
  503.  
  504.      The following example sets the value of `bar' to `23', and gives
  505.      it a documentation string:
  506.  
  507.           (defvar bar 23
  508.             "The normal weight of a bar.")
  509.                => bar
  510.  
  511.      The following form changes the documentation string for `bar',
  512.      making it a user option, but does not change the value, since `bar'
  513.      already has a value.  (The addition `(1+ 23)' is not even
  514.      performed.)
  515.  
  516.           (defvar bar (1+ 23)
  517.             "*The normal weight of a bar.")
  518.                => bar
  519.           bar
  520.                => 23
  521.  
  522.      Here is an equivalent expression for the `defvar' special form:
  523.  
  524.           (defvar SYMBOL VALUE DOC-STRING)
  525.           ==
  526.           (progn
  527.             (if (not (boundp 'SYMBOL))
  528.                 (setq SYMBOL VALUE))
  529.             (put 'SYMBOL 'variable-documentation 'DOC-STRING)
  530.             'SYMBOL)
  531.  
  532.      The `defvar' form returns SYMBOL, but it is normally used at top
  533.      level in a file where its value does not matter.
  534.  
  535.  - Special Form: defconst SYMBOL [VALUE [DOC-STRING]]
  536.      This special form defines SYMBOL as a value and initializes it.
  537.      It informs a person reading your code that SYMBOL has a global
  538.      value, established here, that will not normally be changed or
  539.      locally bound by the execution of the program.  The user, however,
  540.      may be welcome to change it.  Note that SYMBOL is not evaluated;
  541.      the symbol to be defined must appear explicitly in the `defconst'.
  542.  
  543.      `defconst' always evaluates VALUE and sets the global value of
  544.      SYMBOL to the result, provided VALUE is given.  If SYMBOL has a
  545.      buffer-local binding in the current buffer, `defconst' sets the
  546.      default value, not the local value.
  547.  
  548.      *Please note:* Don't use `defconst' for user option variables in
  549.      libraries that are not standardly preloaded.  The user should be
  550.      able to specify a value for such a variable in the `.emacs' file,
  551.      so that it will be in effect if and when the library is loaded
  552.      later.
  553.  
  554.      Here, `pi' is a constant that presumably ought not to be changed
  555.      by anyone (attempts by the Indiana State Legislature
  556.      notwithstanding).  As the second form illustrates, however, this
  557.      is only advisory.
  558.  
  559.           (defconst pi 3.1415 "Pi to five places.")
  560.                => pi
  561.           (setq pi 3)
  562.                => pi
  563.           pi
  564.                => 3
  565.  
  566.  - Function: user-variable-p VARIABLE
  567.      This function returns `t' if VARIABLE is a user option--a variable
  568.      intended to be set by the user for customization--and `nil'
  569.      otherwise.  (Variables other than user options exist for the
  570.      internal purposes of Lisp programs, and users need not know about
  571.      them.)
  572.  
  573.      User option variables are distinguished from other variables by the
  574.      first character of the `variable-documentation' property.  If the
  575.      property exists and is a string, and its first character is `*',
  576.      then the variable is a user option.
  577.  
  578.    If a user option variable has a `variable-interactive' property, the
  579. `set-variable' command uses that value to control reading the new value
  580. for the variable.  The property's value is used as if it were the
  581. argument to `interactive'.
  582.  
  583.    *Warning:* If the `defconst' and `defvar' special forms are used
  584. while the variable has a local binding, they set the local binding's
  585. value; the global binding is not changed.  This is not what we really
  586. want.  To prevent it, use these special forms at top level in a file,
  587. where normally no local binding is in effect, and make sure to load the
  588. file before making a local binding for the variable.
  589.  
  590. 
  591. File: lispref.info,  Node: Accessing Variables,  Next: Setting Variables,  Prev: Defining Variables,  Up: Variables
  592.  
  593. Accessing Variable Values
  594. =========================
  595.  
  596.    The usual way to reference a variable is to write the symbol which
  597. names it (*note Symbol Forms::.).  This requires you to specify the
  598. variable name when you write the program.  Usually that is exactly what
  599. you want to do.  Occasionally you need to choose at run time which
  600. variable to reference; then you can use `symbol-value'.
  601.  
  602.  - Function: symbol-value SYMBOL
  603.      This function returns the value of SYMBOL.  This is the value in
  604.      the innermost local binding of the symbol, or its global value if
  605.      it has no local bindings.
  606.  
  607.           (setq abracadabra 5)
  608.                => 5
  609.           (setq foo 9)
  610.                => 9
  611.           
  612.           ;; Here the symbol `abracadabra'
  613.           ;;   is the symbol whose value is examined.
  614.           (let ((abracadabra 'foo))
  615.             (symbol-value 'abracadabra))
  616.                => foo
  617.           
  618.           ;; Here the value of `abracadabra',
  619.           ;;   which is `foo',
  620.           ;;   is the symbol whose value is examined.
  621.           (let ((abracadabra 'foo))
  622.             (symbol-value abracadabra))
  623.                => 9
  624.           
  625.           (symbol-value 'abracadabra)
  626.                => 5
  627.  
  628.      A `void-variable' error is signaled if SYMBOL has neither a local
  629.      binding nor a global value.
  630.  
  631. 
  632. File: lispref.info,  Node: Setting Variables,  Next: Variable Scoping,  Prev: Accessing Variables,  Up: Variables
  633.  
  634. How to Alter a Variable Value
  635. =============================
  636.  
  637.    The usual way to change the value of a variable is with the special
  638. form `setq'.  When you need to compute the choice of variable at run
  639. time, use the function `set'.
  640.  
  641.  - Special Form: setq [SYMBOL FORM]...
  642.      This special form is the most common method of changing a
  643.      variable's value.  Each SYMBOL is given a new value, which is the
  644.      result of evaluating the corresponding FORM.  The most-local
  645.      existing binding of the symbol is changed.
  646.  
  647.      `setq' does not evaluate SYMBOL; it sets the symbol that you
  648.      write.  We say that this argument is "automatically quoted".  The
  649.      `q' in `setq' stands for "quoted."
  650.  
  651.      The value of the `setq' form is the value of the last FORM.
  652.  
  653.           (setq x (1+ 2))
  654.                => 3
  655.           x                   ; `x' now has a global value.
  656.                => 3
  657.           (let ((x 5))
  658.             (setq x 6)        ; The local binding of `x' is set.
  659.             x)
  660.                => 6
  661.           x                   ; The global value is unchanged.
  662.                => 3
  663.  
  664.      Note that the first FORM is evaluated, then the first SYMBOL is
  665.      set, then the second FORM is evaluated, then the second SYMBOL is
  666.      set, and so on:
  667.  
  668.           (setq x 10          ; Notice that `x' is set before
  669.                 y (1+ x))     ;   the value of `y' is computed.
  670.                => 11
  671.  
  672.  - Function: set SYMBOL VALUE
  673.      This function sets SYMBOL's value to VALUE, then returns VALUE.
  674.      Since `set' is a function, the expression written for SYMBOL is
  675.      evaluated to obtain the symbol to set.
  676.  
  677.      The most-local existing binding of the variable is the binding
  678.      that is set; shadowed bindings are not affected.
  679.  
  680.           (set one 1)
  681.           error--> Symbol's value as variable is void: one
  682.           (set 'one 1)
  683.                => 1
  684.           (set 'two 'one)
  685.                => one
  686.           (set two 2)         ; `two' evaluates to symbol `one'.
  687.                => 2
  688.           one                 ; So it is `one' that was set.
  689.                => 2
  690.           (let ((one 1))      ; This binding of `one' is set,
  691.             (set 'one 3)      ;   not the global value.
  692.             one)
  693.                => 3
  694.           one
  695.                => 2
  696.  
  697.      If SYMBOL is not actually a symbol, a `wrong-type-argument' error
  698.      is signaled.
  699.  
  700.           (set '(x y) 'z)
  701.           error--> Wrong type argument: symbolp, (x y)
  702.  
  703.      Logically speaking, `set' is a more fundamental primitive than
  704.      `setq'.  Any use of `setq' can be trivially rewritten to use
  705.      `set'; `setq' could even be defined as a macro, given the
  706.      availability of `set'.  However, `set' itself is rarely used;
  707.      beginners hardly need to know about it.  It is useful only for
  708.      choosing at run time which variable to set.  For example, the
  709.      command `set-variable', which reads a variable name from the user
  710.      and then sets the variable, needs to use `set'.
  711.  
  712.           Common Lisp note: In Common Lisp, `set' always changes the
  713.           symbol's special value, ignoring any lexical bindings.  In
  714.           XEmacs Lisp, all variables and all bindings are (in effect)
  715.           special, so `set' always affects the most local existing
  716.           binding.
  717.  
  718.    One other function for setting a variable is designed to add an
  719. element to a list if it is not already present in the list.
  720.  
  721.  - Function: add-to-list SYMBOL ELEMENT
  722.      This function sets the variable SYMBOL by consing ELEMENT onto the
  723.      old value, if ELEMENT is not already a member of that value.  It
  724.      returns the resulting list, whether updated or not.  The value of
  725.      SYMBOL had better be a list already before the call.
  726.  
  727.      The argument SYMBOL is not implicitly quoted; `add-to-list' is an
  728.      ordinary function, like `set' and unlike `setq'.  Quote the
  729.      argument yourself if that is what you want.
  730.  
  731.      Here's a scenario showing how to use `add-to-list':
  732.  
  733.           (setq foo '(a b))
  734.                => (a b)
  735.           
  736.           (add-to-list 'foo 'c)     ;; Add `c'.
  737.                => (c a b)
  738.           
  739.           (add-to-list 'foo 'b)     ;; No effect.
  740.                => (c a b)
  741.           
  742.           foo                       ;; `foo' was changed.
  743.                => (c a b)
  744.  
  745.    An equivalent expression for `(add-to-list 'VAR VALUE)' is this:
  746.  
  747.      (or (member VALUE VAR)
  748.          (setq VAR (cons VALUE VAR)))
  749.  
  750. 
  751. File: lispref.info,  Node: Variable Scoping,  Next: Buffer-Local Variables,  Prev: Setting Variables,  Up: Variables
  752.  
  753. Scoping Rules for Variable Bindings
  754. ===================================
  755.  
  756.    A given symbol `foo' may have several local variable bindings,
  757. established at different places in the Lisp program, as well as a global
  758. binding.  The most recently established binding takes precedence over
  759. the others.
  760.  
  761.    Local bindings in XEmacs Lisp have "indefinite scope" and "dynamic
  762. extent".  "Scope" refers to *where* textually in the source code the
  763. binding can be accessed.  Indefinite scope means that any part of the
  764. program can potentially access the variable binding.  "Extent" refers
  765. to *when*, as the program is executing, the binding exists.  Dynamic
  766. extent means that the binding lasts as long as the activation of the
  767. construct that established it.
  768.  
  769.    The combination of dynamic extent and indefinite scope is called
  770. "dynamic scoping".  By contrast, most programming languages use
  771. "lexical scoping", in which references to a local variable must be
  772. located textually within the function or block that binds the variable.
  773.  
  774.      Common Lisp note: Variables declared "special" in Common Lisp are
  775.      dynamically scoped, like variables in XEmacs Lisp.
  776.  
  777. * Menu:
  778.  
  779. * Scope::          Scope means where in the program a value is visible.
  780.                      Comparison with other languages.
  781. * Extent::         Extent means how long in time a value exists.
  782. * Impl of Scope::  Two ways to implement dynamic scoping.
  783. * Using Scoping::  How to use dynamic scoping carefully and avoid problems.
  784.  
  785. 
  786. File: lispref.info,  Node: Scope,  Next: Extent,  Up: Variable Scoping
  787.  
  788. Scope
  789. -----
  790.  
  791.    XEmacs Lisp uses "indefinite scope" for local variable bindings.
  792. This means that any function anywhere in the program text might access a
  793. given binding of a variable.  Consider the following function
  794. definitions:
  795.  
  796.      (defun binder (x)   ; `x' is bound in `binder'.
  797.         (foo 5))         ; `foo' is some other function.
  798.      
  799.      (defun user ()      ; `x' is used in `user'.
  800.        (list x))
  801.  
  802.    In a lexically scoped language, the binding of `x' in `binder' would
  803. never be accessible in `user', because `user' is not textually
  804. contained within the function `binder'.  However, in dynamically scoped
  805. XEmacs Lisp, `user' may or may not refer to the binding of `x'
  806. established in `binder', depending on circumstances:
  807.  
  808.    * If we call `user' directly without calling `binder' at all, then
  809.      whatever binding of `x' is found, it cannot come from `binder'.
  810.  
  811.    * If we define `foo' as follows and call `binder', then the binding
  812.      made in `binder' will be seen in `user':
  813.  
  814.           (defun foo (lose)
  815.             (user))
  816.  
  817.    * If we define `foo' as follows and call `binder', then the binding
  818.      made in `binder' *will not* be seen in `user':
  819.  
  820.           (defun foo (x)
  821.             (user))
  822.  
  823.      Here, when `foo' is called by `binder', it binds `x'.  (The
  824.      binding in `foo' is said to "shadow" the one made in `binder'.)
  825.      Therefore, `user' will access the `x' bound by `foo' instead of
  826.      the one bound by `binder'.
  827.  
  828. 
  829. File: lispref.info,  Node: Extent,  Next: Impl of Scope,  Prev: Scope,  Up: Variable Scoping
  830.  
  831. Extent
  832. ------
  833.  
  834.    "Extent" refers to the time during program execution that a variable
  835. name is valid.  In XEmacs Lisp, a variable is valid only while the form
  836. that bound it is executing.  This is called "dynamic extent".  "Local"
  837. or "automatic" variables in most languages, including C and Pascal,
  838. have dynamic extent.
  839.  
  840.    One alternative to dynamic extent is "indefinite extent".  This
  841. means that a variable binding can live on past the exit from the form
  842. that made the binding.  Common Lisp and Scheme, for example, support
  843. this, but XEmacs Lisp does not.
  844.  
  845.    To illustrate this, the function below, `make-add', returns a
  846. function that purports to add N to its own argument M.  This would work
  847. in Common Lisp, but it does not work as intended in XEmacs Lisp,
  848. because after the call to `make-add' exits, the variable `n' is no
  849. longer bound to the actual argument 2.
  850.  
  851.      (defun make-add (n)
  852.          (function (lambda (m) (+ n m))))  ; Return a function.
  853.           => make-add
  854.      (fset 'add2 (make-add 2))  ; Define function `add2'
  855.                                 ;   with `(make-add 2)'.
  856.           => (lambda (m) (+ n m))
  857.      (add2 4)                   ; Try to add 2 to 4.
  858.      error--> Symbol's value as variable is void: n
  859.  
  860.    Some Lisp dialects have "closures", objects that are like functions
  861. but record additional variable bindings.  XEmacs Lisp does not have
  862. closures.
  863.  
  864. 
  865. File: lispref.info,  Node: Impl of Scope,  Next: Using Scoping,  Prev: Extent,  Up: Variable Scoping
  866.  
  867. Implementation of Dynamic Scoping
  868. ---------------------------------
  869.  
  870.    A simple sample implementation (which is not how XEmacs Lisp actually
  871. works) may help you understand dynamic binding.  This technique is
  872. called "deep binding" and was used in early Lisp systems.
  873.  
  874.    Suppose there is a stack of bindings: variable-value pairs.  At entry
  875. to a function or to a `let' form, we can push bindings on the stack for
  876. the arguments or local variables created there.  We can pop those
  877. bindings from the stack at exit from the binding construct.
  878.  
  879.    We can find the value of a variable by searching the stack from top
  880. to bottom for a binding for that variable; the value from that binding
  881. is the value of the variable.  To set the variable, we search for the
  882. current binding, then store the new value into that binding.
  883.  
  884.    As you can see, a function's bindings remain in effect as long as it
  885. continues execution, even during its calls to other functions.  That is
  886. why we say the extent of the binding is dynamic.  And any other function
  887. can refer to the bindings, if it uses the same variables while the
  888. bindings are in effect.  That is why we say the scope is indefinite.
  889.  
  890.    The actual implementation of variable scoping in XEmacs Lisp uses a
  891. technique called "shallow binding".  Each variable has a standard place
  892. in which its current value is always found--the value cell of the
  893. symbol.
  894.  
  895.    In shallow binding, setting the variable works by storing a value in
  896. the value cell.  Creating a new binding works by pushing the old value
  897. (belonging to a previous binding) on a stack, and storing the local
  898. value in the value cell.  Eliminating a binding works by popping the
  899. old value off the stack, into the value cell.
  900.  
  901.    We use shallow binding because it has the same results as deep
  902. binding, but runs faster, since there is never a need to search for a
  903. binding.
  904.  
  905. 
  906. File: lispref.info,  Node: Using Scoping,  Prev: Impl of Scope,  Up: Variable Scoping
  907.  
  908. Proper Use of Dynamic Scoping
  909. -----------------------------
  910.  
  911.    Binding a variable in one function and using it in another is a
  912. powerful technique, but if used without restraint, it can make programs
  913. hard to understand.  There are two clean ways to use this technique:
  914.  
  915.    * Use or bind the variable only in a few related functions, written
  916.      close together in one file.  Such a variable is used for
  917.      communication within one program.
  918.  
  919.      You should write comments to inform other programmers that they
  920.      can see all uses of the variable before them, and to advise them
  921.      not to add uses elsewhere.
  922.  
  923.    * Give the variable a well-defined, documented meaning, and make all
  924.      appropriate functions refer to it (but not bind it or set it)
  925.      wherever that meaning is relevant.  For example, the variable
  926.      `case-fold-search' is defined as "non-`nil' means ignore case when
  927.      searching"; various search and replace functions refer to it
  928.      directly or through their subroutines, but do not bind or set it.
  929.  
  930.      Then you can bind the variable in other programs, knowing reliably
  931.      what the effect will be.
  932.  
  933.    In either case, you should define the variable with `defvar'.  This
  934. helps other people understand your program by telling them to look for
  935. inter-function usage.  It also avoids a warning from the byte compiler.
  936. Choose the variable's name to avoid name conflicts--don't use short
  937. names like `x'.
  938.  
  939. 
  940. File: lispref.info,  Node: Buffer-Local Variables,  Next: Variable Aliases,  Prev: Variable Scoping,  Up: Variables
  941.  
  942. Buffer-Local Variables
  943. ======================
  944.  
  945.    Global and local variable bindings are found in most programming
  946. languages in one form or another.  XEmacs also supports another, unusual
  947. kind of variable binding: "buffer-local" bindings, which apply only to
  948. one buffer.  XEmacs Lisp is meant for programming editing commands, and
  949. having different values for a variable in different buffers is an
  950. important customization method.
  951.  
  952. * Menu:
  953.  
  954. * Intro to Buffer-Local::      Introduction and concepts.
  955. * Creating Buffer-Local::      Creating and destroying buffer-local bindings.
  956. * Default Value::              The default value is seen in buffers
  957.                                  that don't have their own local values.
  958.  
  959. 
  960. File: lispref.info,  Node: Intro to Buffer-Local,  Next: Creating Buffer-Local,  Up: Buffer-Local Variables
  961.  
  962. Introduction to Buffer-Local Variables
  963. --------------------------------------
  964.  
  965.    A buffer-local variable has a buffer-local binding associated with a
  966. particular buffer.  The binding is in effect when that buffer is
  967. current; otherwise, it is not in effect.  If you set the variable while
  968. a buffer-local binding is in effect, the new value goes in that binding,
  969. so the global binding is unchanged; this means that the change is
  970. visible in that buffer alone.
  971.  
  972.    A variable may have buffer-local bindings in some buffers but not in
  973. others.  The global binding is shared by all the buffers that don't have
  974. their own bindings.  Thus, if you set the variable in a buffer that does
  975. not have a buffer-local binding for it, the new value is visible in all
  976. buffers except those with buffer-local bindings.  (Here we are assuming
  977. that there are no `let'-style local bindings to complicate the issue.)
  978.  
  979.    The most common use of buffer-local bindings is for major modes to
  980. change variables that control the behavior of commands.  For example, C
  981. mode and Lisp mode both set the variable `paragraph-start' to specify
  982. that only blank lines separate paragraphs.  They do this by making the
  983. variable buffer-local in the buffer that is being put into C mode or
  984. Lisp mode, and then setting it to the new value for that mode.
  985.  
  986.    The usual way to make a buffer-local binding is with
  987. `make-local-variable', which is what major mode commands use.  This
  988. affects just the current buffer; all other buffers (including those yet
  989. to be created) continue to share the global value.
  990.  
  991.    A more powerful operation is to mark the variable as "automatically
  992. buffer-local" by calling `make-variable-buffer-local'.  You can think
  993. of this as making the variable local in all buffers, even those yet to
  994. be created.  More precisely, the effect is that setting the variable
  995. automatically makes the variable local to the current buffer if it is
  996. not already so.  All buffers start out by sharing the global value of
  997. the variable as usual, but any `setq' creates a buffer-local binding
  998. for the current buffer.  The new value is stored in the buffer-local
  999. binding, leaving the (default) global binding untouched.  The global
  1000. value can no longer be changed with `setq'; you need to use
  1001. `setq-default' to do that.
  1002.  
  1003.    Local variables in a file you edit are also represented by
  1004. buffer-local bindings for the buffer that holds the file within XEmacs.
  1005. *Note Auto Major Mode::.
  1006.  
  1007. 
  1008. File: lispref.info,  Node: Creating Buffer-Local,  Next: Default Value,  Prev: Intro to Buffer-Local,  Up: Buffer-Local Variables
  1009.  
  1010. Creating and Deleting Buffer-Local Bindings
  1011. -------------------------------------------
  1012.  
  1013.  - Command: make-local-variable VARIABLE
  1014.      This function creates a buffer-local binding in the current buffer
  1015.      for VARIABLE (a symbol).  Other buffers are not affected.  The
  1016.      value returned is VARIABLE.
  1017.  
  1018.      The buffer-local value of VARIABLE starts out as the same value
  1019.      VARIABLE previously had.  If VARIABLE was void, it remains void.
  1020.  
  1021.           ;; In buffer `b1':
  1022.           (setq foo 5)                ; Affects all buffers.
  1023.                => 5
  1024.           (make-local-variable 'foo)  ; Now it is local in `b1'.
  1025.                => foo
  1026.           foo                         ; That did not change
  1027.                => 5                   ;   the value.
  1028.           (setq foo 6)                ; Change the value
  1029.                => 6                   ;   in `b1'.
  1030.           foo
  1031.                => 6
  1032.           
  1033.           ;; In buffer `b2', the value hasn't changed.
  1034.           (save-excursion
  1035.             (set-buffer "b2")
  1036.             foo)
  1037.                => 5
  1038.  
  1039.      Making a variable buffer-local within a `let'-binding for that
  1040.      variable does not work.  This is because `let' does not distinguish
  1041.      between different kinds of bindings; it knows only which variable
  1042.      the binding was made for.
  1043.  
  1044.      *Note:* do not use `make-local-variable' for a hook variable.
  1045.      Instead, use `make-local-hook'.  *Note Hooks::.
  1046.  
  1047.  - Command: make-variable-buffer-local VARIABLE
  1048.      This function marks VARIABLE (a symbol) automatically
  1049.      buffer-local, so that any subsequent attempt to set it will make it
  1050.      local to the current buffer at the time.
  1051.  
  1052.      The value returned is VARIABLE.
  1053.  
  1054.  - Function: local-variable-p VARIABLE &optional BUFFER
  1055.      This returns `t' if VARIABLE is buffer-local in buffer BUFFER
  1056.      (which defaults to the current buffer); otherwise, `nil'.
  1057.  
  1058.  - Function: buffer-local-variables &optional BUFFER
  1059.      This function returns a list describing the buffer-local variables
  1060.      in buffer BUFFER.  It returns an association list (*note
  1061.      Association Lists::.) in which each association contains one
  1062.      buffer-local variable and its value.  When a buffer-local variable
  1063.      is void in BUFFER, then it appears directly in the resulting list.
  1064.      If BUFFER is omitted, the current buffer is used.
  1065.  
  1066.           (make-local-variable 'foobar)
  1067.           (makunbound 'foobar)
  1068.           (make-local-variable 'bind-me)
  1069.           (setq bind-me 69)
  1070.           (setq lcl (buffer-local-variables))
  1071.               ;; First, built-in variables local in all buffers:
  1072.           => ((mark-active . nil)
  1073.               (buffer-undo-list nil)
  1074.               (mode-name . "Fundamental")
  1075.               ...
  1076.               ;; Next, non-built-in local variables.
  1077.               ;; This one is local and void:
  1078.               foobar
  1079.               ;; This one is local and nonvoid:
  1080.               (bind-me . 69))
  1081.  
  1082.      Note that storing new values into the CDRs of cons cells in this
  1083.      list does *not* change the local values of the variables.
  1084.  
  1085.  - Command: kill-local-variable VARIABLE
  1086.      This function deletes the buffer-local binding (if any) for
  1087.      VARIABLE (a symbol) in the current buffer.  As a result, the
  1088.      global (default) binding of VARIABLE becomes visible in this
  1089.      buffer.  Usually this results in a change in the value of
  1090.      VARIABLE, since the global value is usually different from the
  1091.      buffer-local value just eliminated.
  1092.  
  1093.      If you kill the local binding of a variable that automatically
  1094.      becomes local when set, this makes the global value visible in the
  1095.      current buffer.  However, if you set the variable again, that will
  1096.      once again create a local binding for it.
  1097.  
  1098.      `kill-local-variable' returns VARIABLE.
  1099.  
  1100.      This function is a command because it is sometimes useful to kill
  1101.      one buffer-local variable interactively, just as it is useful to
  1102.      create buffer-local variables interactively.
  1103.  
  1104.  - Function: kill-all-local-variables
  1105.      This function eliminates all the buffer-local variable bindings of
  1106.      the current buffer except for variables marked as "permanent".  As
  1107.      a result, the buffer will see the default values of most variables.
  1108.  
  1109.      This function also resets certain other information pertaining to
  1110.      the buffer: it sets the local keymap to `nil', the syntax table to
  1111.      the value of `standard-syntax-table', and the abbrev table to the
  1112.      value of `fundamental-mode-abbrev-table'.
  1113.  
  1114.      Every major mode command begins by calling this function, which
  1115.      has the effect of switching to Fundamental mode and erasing most
  1116.      of the effects of the previous major mode.  To ensure that this
  1117.      does its job, the variables that major modes set should not be
  1118.      marked permanent.
  1119.  
  1120.      `kill-all-local-variables' returns `nil'.
  1121.  
  1122.    A local variable is "permanent" if the variable name (a symbol) has a
  1123. `permanent-local' property that is non-`nil'.  Permanent locals are
  1124. appropriate for data pertaining to where the file came from or how to
  1125. save it, rather than with how to edit the contents.
  1126.  
  1127. 
  1128. File: lispref.info,  Node: Default Value,  Prev: Creating Buffer-Local,  Up: Buffer-Local Variables
  1129.  
  1130. The Default Value of a Buffer-Local Variable
  1131. --------------------------------------------
  1132.  
  1133.    The global value of a variable with buffer-local bindings is also
  1134. called the "default" value, because it is the value that is in effect
  1135. except when specifically overridden.
  1136.  
  1137.    The functions `default-value' and `setq-default' access and change a
  1138. variable's default value regardless of whether the current buffer has a
  1139. buffer-local binding.  For example, you could use `setq-default' to
  1140. change the default setting of `paragraph-start' for most buffers; and
  1141. this would work even when you are in a C or Lisp mode buffer that has a
  1142. buffer-local value for this variable.
  1143.  
  1144.    The special forms `defvar' and `defconst' also set the default value
  1145. (if they set the variable at all), rather than any local value.
  1146.  
  1147.  - Function: default-value SYMBOL
  1148.      This function returns SYMBOL's default value.  This is the value
  1149.      that is seen in buffers that do not have their own values for this
  1150.      variable.  If SYMBOL is not buffer-local, this is equivalent to
  1151.      `symbol-value' (*note Accessing Variables::.).
  1152.  
  1153.  - Function: default-boundp SYMBOL
  1154.      The function `default-boundp' tells you whether SYMBOL's default
  1155.      value is nonvoid.  If `(default-boundp 'foo)' returns `nil', then
  1156.      `(default-value 'foo)' would get an error.
  1157.  
  1158.      `default-boundp' is to `default-value' as `boundp' is to
  1159.      `symbol-value'.
  1160.  
  1161.  - Special Form: setq-default SYMBOL VALUE
  1162.      This sets the default value of SYMBOL to VALUE.  It does not
  1163.      evaluate SYMBOL, but does evaluate VALUE.  The value of the
  1164.      `setq-default' form is VALUE.
  1165.  
  1166.      If a SYMBOL is not buffer-local for the current buffer, and is not
  1167.      marked automatically buffer-local, `setq-default' has the same
  1168.      effect as `setq'.  If SYMBOL is buffer-local for the current
  1169.      buffer, then this changes the value that other buffers will see
  1170.      (as long as they don't have a buffer-local value), but not the
  1171.      value that the current buffer sees.
  1172.  
  1173.           ;; In buffer `foo':
  1174.           (make-local-variable 'local)
  1175.                => local
  1176.           (setq local 'value-in-foo)
  1177.                => value-in-foo
  1178.           (setq-default local 'new-default)
  1179.                => new-default
  1180.           local
  1181.                => value-in-foo
  1182.           (default-value 'local)
  1183.                => new-default
  1184.           
  1185.           ;; In (the new) buffer `bar':
  1186.           local
  1187.                => new-default
  1188.           (default-value 'local)
  1189.                => new-default
  1190.           (setq local 'another-default)
  1191.                => another-default
  1192.           (default-value 'local)
  1193.                => another-default
  1194.           
  1195.           ;; Back in buffer `foo':
  1196.           local
  1197.                => value-in-foo
  1198.           (default-value 'local)
  1199.                => another-default
  1200.  
  1201.  - Function: set-default SYMBOL VALUE
  1202.      This function is like `setq-default', except that SYMBOL is
  1203.      evaluated.
  1204.  
  1205.           (set-default (car '(a b c)) 23)
  1206.                => 23
  1207.           (default-value 'a)
  1208.                => 23
  1209.  
  1210.